package com.proyecto.track.action;

import java.util.*;

import com.opensymphony.xwork2.ActionSupport;
import com.proyecto.track.bo.ItemAutoComplete;
import com.proyecto.track.bo.UserPerson;
import com.proyecto.track.service.UserPersonService;


public class UserPersonAutoCompleteAction extends ActionSupport {
	private static final long serialVersionUID = 1L;
	
	private UserPersonService userPersonService;
	private String term;
	private List<ItemAutoComplete> items = new ArrayList<ItemAutoComplete>();
	
	public String searchUserPersons() {
		List<UserPerson> userPersons = userPersonService.searchUser(term);
		String labelActual = "";
		for (UserPerson userPerson : userPersons) {
			labelActual = userPerson.getName() + " " + userPerson.getLastName();
			items.add(new ItemAutoComplete(userPerson.getId(), labelActual, labelActual));			
		}
		return SUCCESS;
	}

	
	public UserPersonService getUserPersonService() {
		return userPersonService;
	}

	public void setUserPersonService(UserPersonService userPersonService) {
		this.userPersonService = userPersonService;
	}

	public String getTerm() {
		return term;
	}

	public void setTerm(String term) {
		this.term = term;
	}

	public List<ItemAutoComplete> getItems() {
		return items;
	}

	public void setItems(List<ItemAutoComplete> items) {
		this.items = items;
	}

}
